package com.hiwhitley.easy.day23;

import java.util.Stack;

/**
 * Created by hiwhitley on 2016/10/15.
 */
public class MinStack {
    Stack<Integer> stackData;
    Stack<Integer> stackMin;

    public MinStack() {
        stackData = new Stack<>();
        stackMin = new Stack<>();
    }

    public void push(int x) {
        stackData.push(x);
        stackMin.push(Math.min(x, stackMin.size() > 0 ? getMin() : x));
    }

    public void pop() {
        stackMin.pop();
        stackData.pop();
    }

    public int top() {
        return stackData.peek();
    }

    public int getMin() {
        return stackMin.peek();
    }
}
